#include "CollisionData.h"

namespace binge
{

CollisionData::CollisionData(void)
{

}

CollisionData::~CollisionData(void)
{
    objectsType.clear();
    objectsRectangle.clear();
    objectsTile.clear();
}

void
CollisionData::AddObject(int id)
{
    sf::Rect<float> rect;

    objectsId.push_back(id);
    objectsType.push_back(COLLISION_RECT);
    objectsRectangle.push_back(rect);
    objectsTile.push_back(false);
}

void
CollisionData::RemoveObject(int id)
{
    int index = GetIndex(id);
    objectsId.erase(objectsId.begin()+index);
    objectsType.erase(objectsType.begin()+index);
    objectsRectangle.erase(objectsRectangle.begin()+index);
    objectsTile.erase(objectsTile.begin()+index);
}

void
CollisionData::SetType(int id, CollisionType type)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsType[index] = type;
    }
}

CollisionType
CollisionData::GetType(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsType[index];
    }
    return COLLISION_NONE;
}

void
CollisionData::SetRectangle(int id, sf::Rect<float> rect)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsRectangle[index] = rect;
    }
}

void
CollisionData::SetLeft(int id, float left)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsRectangle[index].Left = left;
    }
}

void
CollisionData::SetTop(int id, float top)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsRectangle[index].Top = top;
    }
}

void
CollisionData::SetRight(int id, float right)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsRectangle[index].Right = right;
    }
}

void
CollisionData::SetBottom(int id, float bottom)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsRectangle[index].Bottom = bottom;
    }
}

sf::Rect<float>
CollisionData::GetRectangle(int id)
{
    sf::Rect<float> rect;
    int index = GetIndex(id);
    if (index != -1)
    {
        rect = objectsRectangle[index];
    }
    return rect;
}

float
CollisionData::GetLeft(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsRectangle[index].Left;
    }
    return 0;
}

float
CollisionData::GetTop(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsRectangle[index].Top;
    }
    return 0;
}

float
CollisionData::GetRight(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsRectangle[index].Right;
    }
    return 0;
}

float
CollisionData::GetBottom(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsRectangle[index].Bottom;
    }
    return 0;
}

void
CollisionData::SetTile(int id, bool value)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsTile[index] = value;
    }
}

bool
CollisionData::IsTile(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsTile[index];
    }
    return false;
}

} // namespace
